﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;

namespace ERP.Classes
{
    public class cs_hmr_nv_pbInfo
    {
        private string _manvpb;
        private int _manhanvien;
        private string _maphongban;
        private string _chucdanh;
        private DateTime _ngaybatdau;
        private DateTime _ngayketthuc;
        private int _sep;
        private int _trangthai;
        private string _mahd;
        private string _soqd;
        private string _noidungqd;
        private string _ngayqd;
        private string _ngaynhap;
        private int _nguoinhap;
        private string _ngaysua;
        private int _nguoisua;

        
        public cs_hmr_nv_pbInfo()
        {
            this._manvpb = " ";
            this._manhanvien = 0;
            this._maphongban = " ";
            this._chucdanh = " ";
            this._ngaybatdau = Convert.ToDateTime("01/01/9999");
            this._ngayketthuc = Convert.ToDateTime("01/01/9999");
            this._sep = 0;
            this._trangthai = 0;
            this._mahd = " ";
            this._soqd = " ";
            this._noidungqd = " ";
            this._ngayqd = " ";
            this._ngaynhap = " ";
            this._nguoinhap = 0;
            this._ngaysua = " ";
            this._nguoisua = 0;

        }
        public string manvpb
        {
            get
            {
                return this._manvpb;
            }
            set
            {
                this._manvpb = value;
            }
        }
        public int manhanvien
        {
            get
            {
                return this._manhanvien;
            }
            set
            {
                this._manhanvien = value;
            }
        }
        public string maphongban
        {
            get
            {
                return this._maphongban;
            }
            set
            {
                this._maphongban = value;
            }
        }
        public string chucdanh
        {
            get
            {
                return this._chucdanh;
            }
            set
            {
                this._chucdanh = value;
            }
        }
        public DateTime ngaybatdau
        {
            get
            {
                return this._ngaybatdau;
            }
            set
            {
                this._ngaybatdau = value;
            }
        }
        public DateTime ngayketthuc
        {
            get
            {
                return this._ngayketthuc;
            }
            set
            {
                this._ngayketthuc = value;
            }
        }
        public int sep
        {
            get
            {
                return this._sep;
            }
            set
            {
                this._sep = value;
            }
        }
        public int trangthai
        {
            get
            {
                return this._trangthai;
            }
            set
            {
                this._trangthai = value;
            }
        }
        public string mahd
        {
            get
            {
                return this._mahd;
            }
            set
            {
                this._mahd = value;
            }
        }
        public string soqd
        {
            get
            {
                return this._soqd;
            }
            set
            {
                this._soqd = value;
            }
        }
        public string noidungqd
        {
            get
            {
                return this._noidungqd;
            }
            set
            {
                this._noidungqd = value;
            }
        }
        public string ngayqd
        {
            get
            {
                return this._ngayqd;
            }
            set
            {
                this._ngayqd = value;
            }
        }
        public string ngaynhap
        {
            get
            {
                return this._ngaynhap;
            }
            set
            {
                this._ngaynhap = value;
            }
        }
        public int nguoinhap
        {
            get
            {
                return this._nguoinhap;
            }
            set
            {
                this._nguoinhap = value;
            }
        }
        public string ngaysua
        {
            get
            {
                return this._ngaysua;
            }
            set
            {
                this._ngaysua = value;
            }
        }
        public int nguoisua
        {
            get
            {
                return this._nguoisua;
            }
            set
            {
                this._nguoisua = value;
            }
        }

        public int ExcuteStoreProcedure(string storeProcedure, int option)
        {
            string[] paraName = new string[17];
            paraName[0] = "@manvpb";
            paraName[1] = "@manhanvien";
            paraName[2] = "@maphongban";
            paraName[3] = "@chucdanh";
            paraName[4] = "@ngaybatdau";
            paraName[5] = "@ngayketthuc";
            paraName[6] = "@sep";
            paraName[7] = "@trangthai";
            paraName[8] = "@mahd";
            paraName[9] = "@soqd";
            paraName[10] = "@noidungqd";
            paraName[11] = "@ngayqd";
            paraName[12] = "@ngaynhap";
            paraName[13] = "@nguoinhap";
            paraName[14] = "@ngaysua";
            paraName[15] = "@nguoisua";
            paraName[16] = "@option";
            object[] paraValue = new object[17];
            paraValue[0] = this._manvpb;
            paraValue[1] = this._manhanvien;
            paraValue[2] = this._maphongban;
            paraValue[3] = this._chucdanh;
            paraValue[4] = this._ngaybatdau;
            paraValue[5] = this._ngayketthuc;
            paraValue[6] = this._sep;
            paraValue[7] = this._trangthai;
            paraValue[8] = this._mahd;
            paraValue[9] = this._soqd;
            paraValue[10] = this._noidungqd;
            paraValue[11] = this._ngayqd;
            paraValue[12] = this._ngaynhap;
            paraValue[13] = this._nguoinhap;
            paraValue[14] = this._ngaysua;
            paraValue[15] = this._nguoisua;
            paraValue[16] = option;
            csCSDL csdl = new csCSDL();
            int i = 0;
            i = csdl.CreateParameters(paraName, 17, paraValue);
            return csdl.ExcuteStoreProcedure(storeProcedure);
        }
        public void KetDulieuVaoListview(ListView myList)
        {
            csListView list = new csListView();
            string[] fields = new string[16];
            fields[0] = "manvpb";
            fields[1] = "manhanvien";
            fields[2] = "maphongban";
            fields[3] = "chucdanh";
            fields[4] = "ngaybatdau";
            fields[5] = "ngayketthuc";
            fields[6] = "sep";
            fields[7] = "trangthai";
            fields[8] = "mahd";
            fields[9] = "soqd";
            fields[10] = "noidungqd";
            fields[11] = "ngayqd";
            fields[12] = "ngaynhap";
            fields[13] = "nguoinhap";
            fields[14] = "ngaysua";
            fields[15] = "nguoisua";
            list.KetDulieu(myList, "HMR_NV_PB", "", fields);
        }
        public int ExcuteProcedure(int option)
        {
            return this.ExcuteStoreProcedure("Proc_HMR_NV_PB", option);
        }

        public void ShowDataInCombo(ComboBox cbo, string condition)
        {
            csComboBox cb = new csComboBox("manhanvien", "manvpb");
            cb.KetDuLieu(cbo, "HMR_NV_PB", condition);
        }

        public int ShowDataGrid(DataGrid datagrid, string condition)
        {
            csDataGrid grid = new csDataGrid();

            string[] header = new string[16];
            header[0] = "manvpb";
            header[1] = "manhanvien";
            header[2] = "maphongban";
            header[3] = "chucdanh";
            header[4] = "ngaybatdau";
            header[5] = "ngayketthuc";
            header[6] = "sep";
            header[7] = "trangthai";
            header[8] = "mahd";
            header[9] = "soqd";
            header[10] = "noidungqd";
            header[11] = "ngayqd";
            header[12] = "ngaynhap";
            header[13] = "nguoinhap";
            header[14] = "ngaysua";
            header[15] = "nguoisua";

            string[] mappingname = new string[16];
            mappingname[0] = "manvpb";
            mappingname[1] = "manhanvien";
            mappingname[2] = "maphongban";
            mappingname[3] = "chucdanh";
            mappingname[4] = "ngaybatdau";
            mappingname[5] = "ngayketthuc";
            mappingname[6] = "sep";
            mappingname[7] = "trangthai";
            mappingname[8] = "mahd";
            mappingname[9] = "soqd";
            mappingname[10] = "noidungqd";
            mappingname[11] = "ngayqd";
            mappingname[12] = "ngaynhap";
            mappingname[13] = "nguoinhap";
            mappingname[14] = "ngaysua";
            mappingname[15] = "nguoisua";

            int[] colwidth = new int[16];
            colwidth[0] = 60;
            colwidth[1] = 12;
            colwidth[2] = 30;
            colwidth[3] = 30;
            colwidth[4] = 24;
            colwidth[5] = 24;
            colwidth[6] = 12;
            colwidth[7] = 12;
            colwidth[8] = 60;
            colwidth[9] = 600;
            colwidth[10] = 2400;
            colwidth[11] = 90;
            colwidth[12] = 90;
            colwidth[13] = 12;
            colwidth[14] = 90;
            colwidth[15] = 12;
            csCSDL csdl = new csCSDL();
            return grid.CreateTableStyle("HMR_NV_PB", datagrid, csdl.OpenTable("HMR_NV_PB", condition), header, mappingname, colwidth, 16);
        }
        public int Get_Info()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                ds = csdl.OpenTable("HMR_NV_PB", "manvpb = '" + this._manvpb + "'");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return 0;
                }
                this._manvpb = ds.Tables[0].Rows[0]["manvpb"].ToString().Trim();
                this._manhanvien = Convert.ToInt32(ds.Tables[0].Rows[0]["manhanvien"].ToString().Trim());
                this._maphongban = ds.Tables[0].Rows[0]["maphongban"].ToString().Trim();
                this._chucdanh = ds.Tables[0].Rows[0]["chucdanh"].ToString().Trim();
                this._ngaybatdau = Convert.ToDateTime(ds.Tables[0].Rows[0]["ngaybatdau"].ToString().Trim());
                this._ngayketthuc = Convert.ToDateTime(ds.Tables[0].Rows[0]["ngayketthuc"].ToString().Trim());
                this._sep = Convert.ToInt32(ds.Tables[0].Rows[0]["sep"].ToString().Trim());
                this._trangthai = Convert.ToInt32(ds.Tables[0].Rows[0]["trangthai"].ToString().Trim());
                this._mahd = ds.Tables[0].Rows[0]["mahd"].ToString().Trim();
                this._soqd = ds.Tables[0].Rows[0]["soqd"].ToString().Trim();
                this._noidungqd = ds.Tables[0].Rows[0]["noidungqd"].ToString().Trim();
                this._ngayqd = ds.Tables[0].Rows[0]["ngayqd"].ToString().Trim();
                this._ngaynhap = ds.Tables[0].Rows[0]["ngaynhap"].ToString().Trim();
                this._nguoinhap = Convert.ToInt32(ds.Tables[0].Rows[0]["nguoinhap"].ToString().Trim());
                this._ngaysua = ds.Tables[0].Rows[0]["ngaysua"].ToString().Trim();
                this._nguoisua = Convert.ToInt32(ds.Tables[0].Rows[0]["nguoisua"].ToString().Trim());
                return 1;
            }
            catch
            {
                return -1;
            }
        }
    }
}
